/*
 * Copyright (c) 2019-2020, https://api.iot.10086.cn/(https://gitee.com/cmcc-iot-api/iot-card-open-application/).
 */
package cn.iot.card.open.ec.controller;

import cn.iot.card.open.ec.dto.groupinfo.EcGroupMemberReqDTO;
import cn.iot.card.open.ec.dto.groupinfo.EcGroupMemberSetFlowReqDTO;
import cn.iot.card.open.ec.dto.groupinfo.EcGroupVoiceWhiteSetReqDTO;
import cn.iot.card.open.ec.service.EcGroupService;
import cn.iot.card.open.modular.log.ApiBussinessLog;
import cn.iot.card.open.util.CommonUtil;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * 集团群组信息
 *
 * @author cmcc-iot-api
 * @date 20191230 09:54:12
 */
@Controller
@RequestMapping("/ecGroup")
public class EcGroupController extends BaseController {

    /**
     * 集团群组信息页面路径前缀
     */
    private static String PREFIX_PAGE = "/modular/ec/group/";

    @Autowired
    private EcGroupService ecGroupService;

    /**
     * 跳转到集团群组信息页面
     *
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("")
    public String index() {
        return PREFIX_PAGE + "group.html";
    }

    /**
     * 查询 集团群组信息
     *
     * @param accountId 集团id
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200119 09:11:23
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String accountId) throws IOException {
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.selectEcGroupInfo(transId, accountId);
    }

    /**
     * 实时查询集团群组本月套餐内流量共享/流量池使用情况
     *
     * @param groupId 群组id
     * @param accountId 集团id
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/shareUseAmount")
    @ResponseBody
    public Object shareUseAmount(@RequestParam String groupId, @RequestParam String accountId) throws IOException {
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.getShareUseAmount(transId, accountId, groupId);
    }

    /**
     * 查询 本月累计GPRS使用量（KB）
     *
     * @param groupId 群组id
     * @param accountId
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/gprsUseAmount")
    @ResponseBody
    public Object gprsUseAmount(@RequestParam String groupId, @RequestParam String accountId) throws IOException {
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.getGprsUseAmount(transId, accountId, groupId);
    }

    /**
     * 跳转到集团群组成员信息页面
     *
     * @param groupId
     * @param accountId
     * @param model
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("/group_member/{groupId}/{accountId}")
    public String memberMgrPage(@PathVariable("groupId") String groupId, @PathVariable("accountId") String accountId, Model model) {
        model.addAttribute("groupId", groupId);
        model.addAttribute("accountId", accountId);
        return PREFIX_PAGE + "group_member.html";
    }

    /**
     * 查询 集团群组成员信息列表
     *
     * @param groupId 群组id
     * @param accountId
     * @param msisdn
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/groupMembers")
    @ResponseBody
    public Object memberList(@RequestParam String groupId, @RequestParam String accountId, @RequestParam(required = false) String msisdn) throws IOException {
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.getGroupMembers(transId, accountId, groupId, msisdn);
    }

    /**
     * 跳转到集团群组成员信息管理页面
     *
     * @param groupId
     * @param accountId
     * @param model
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("/toAddOrDeleteGroupMember/{groupId}/{accountId}")
    public String toAddOrDeleteGroupMember(@PathVariable("groupId")  String groupId, @PathVariable("accountId")  String accountId, Model model) {
        model.addAttribute("groupId", groupId);
        model.addAttribute("accountId", accountId);
        return PREFIX_PAGE + "group_member_add_or_delete.html";
    }

    /**
     * 集团群组成员管理
     *
     * @param ecGroupMemberReqDTO
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/addOrDeleteGroupMember")
    @ApiBussinessLog(value = "添加/删除群组成员")
    @ResponseBody
    public ResponseData addOrDeleteGroupMember(EcGroupMemberReqDTO ecGroupMemberReqDTO) throws IOException {
        String accountId = ecGroupMemberReqDTO.getAccountId();
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.addOrDeleteGroupMember(transId, ecGroupMemberReqDTO);
    }

    /**
     * 跳转到群组成员流量限额设置页面
     *
     * @param groupId
     * @param accountId
     * @param model
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("/toSetGroupMemberFlow/{groupId}/{accountId}")
    public String toSetGroupMemberFlow(@PathVariable("groupId")  String groupId, @PathVariable("accountId")  String accountId, Model model) {
        model.addAttribute("groupId", groupId);
        model.addAttribute("accountId", accountId);
        return PREFIX_PAGE + "group_member_flow_set.html";
    }

    /**
     * 群组成员流量限额设置
     *
     * @param ecGroupMemberSetFlowReqDTO
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/setGroupMemberFlow")
    @ApiBussinessLog(value = "群组成员流量限额设置")
    @ResponseBody
    public ResponseData setGroupMemberFlow(EcGroupMemberSetFlowReqDTO ecGroupMemberSetFlowReqDTO) throws IOException {
        String accountId = ecGroupMemberSetFlowReqDTO.getAccountId();
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.setGroupMemberFlow(transId, ecGroupMemberSetFlowReqDTO);
    }

    /**
     * 跳转到群组已订购资费页面
     *
     * @param groupId
     * @param accountId
     * @param model
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("/group_order/{groupId}/{accountId}")
    public String toGroupOrder(@PathVariable("groupId")  String groupId, @PathVariable("accountId")  String accountId, Model model) {
        model.addAttribute("groupId", groupId);
        model.addAttribute("accountId", accountId);
        return PREFIX_PAGE + "group_order.html";
    }

    /**
     * 群组已订购资费列表
     *
     * @param groupId
     * @param accountId
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/groupOrders")
    @ResponseBody
    public Object groupOrders(@RequestParam String groupId, @RequestParam String accountId) throws IOException {
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.getGroupOrders(transId, accountId, groupId);
    }

    /**
     * 跳转到群组可变更资费页面
     *
     * @param groupId
     * @param accountId
     * @param offeringId
     * @param model
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("/toChangeableOfferings/{groupId}/{accountId}/{offeringId}")
    public String toChangeableOfferings(@PathVariable("groupId")  String groupId, @PathVariable("accountId")  String accountId, @PathVariable("offeringId")  String offeringId, Model model) {
        model.addAttribute("groupId", groupId);
        model.addAttribute("accountId", accountId);
        model.addAttribute("offeringId", offeringId);
        return PREFIX_PAGE + "group_order_changeable.html";
    }

    /**
     * 群组可变更资费列表
     *
     * @param groupId
     * @param accountId
     * @param offeringId
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/changeableOfferings")
    @ResponseBody
    public Object getChangeableOfferings(@RequestParam String groupId, @RequestParam String accountId, @RequestParam String offeringId) throws IOException {
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.getChangeableOfferings(transId, accountId, groupId, offeringId);
    }

    /**
     * 跳转到群组语音白名单页面
     *
     * @param groupId
     * @param accountId
     * @param model
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("/toGroupVoiceWhite/{groupId}/{accountId}")
    public String toGroupVoiceWhite(@PathVariable("groupId")  String groupId, @PathVariable("accountId")  String accountId, Model model) {
        model.addAttribute("groupId", groupId);
        model.addAttribute("accountId", accountId);
        return PREFIX_PAGE + "group_voice_white.html";
    }

    /**
     * 群组语音白名单列表
     *
     * @param groupId
     * @param accountId
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/groupVoiceWhiteList")
    @ResponseBody
    public Object getGroupVoiceWhiteList(@RequestParam String groupId, @RequestParam String accountId, @RequestParam(required = false) String msisdn) throws IOException {
        String transId = CommonUtil.generateTransId(accountId);
        return ecGroupService.getGroupVoiceWhiteList(transId, accountId, groupId, msisdn);
    }

    /**
     * 跳转到配置群组白名单页面
     *
     * @param groupId
     * @param accountId
     * @param model
     * @return 返回 string
     * @author cmcc-iot-api
     * @date 20191230 11:41:07
     */
    @RequestMapping("/toSetGroupVoiceWhite/{groupId}/{accountId}")
    public String toSetVoiceWhite(@PathVariable("groupId")  String groupId, @PathVariable("accountId")  String accountId, Model model) {
        model.addAttribute("groupId", groupId);
        model.addAttribute("accountId", accountId);
        return PREFIX_PAGE + "group_voice_white_set.html";
    }

    /**
     * 配置群组语音白名单
     *
     * @param ecGroupVoiceWhiteSetReqDTO
     * @return 返回 object
     * @throws IOException
     * @author cmcc-iot-api
     * @date 20200109 10:02:28
     */
    @RequestMapping("/setGroupVoiceWhite")
    @ApiBussinessLog(value = "群组语音白名单配置")
    @ResponseBody
    public Object setGroupVoiceWhite(EcGroupVoiceWhiteSetReqDTO ecGroupVoiceWhiteSetReqDTO) throws IOException {
        String transId = CommonUtil.generateTransId(ecGroupVoiceWhiteSetReqDTO.getAccountId());
        return ecGroupService.setGroupVoiceWhite(transId, ecGroupVoiceWhiteSetReqDTO);
    }
}
